<template>
  <div class="salesDataMonth">
    <div class="title">
      <stitle :bg="bg" text="产品销售数据统计" :type="0" />
    </div>
    <el-row :gutter="20" style="position: relative;">
      <el-col :span="4">
    <el-button size="mini" :class="change?'xuanzh':''" @click="chbt(1)">销量</el-button>
      </el-col>
      <el-col :span="4">
    <el-button size="mini" :class="change?'':'xuanzh'" @click="chbt(2)">销售额</el-button>
      </el-col>
      <el-col :span="7">
        <el-select size="mini" v-model="value" placeholder="请选择">
          <el-option
            v-for="item in select"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        </el-col>
    </el-row>
    <div id="echartSalesDataMonth"></div>
  </div>
</template>

<script>
import stitle from "@/components/common/stitle";
export default {
  name: "salesDataMonth",
  components: {
    stitle,
  },
  data() {
    return {
      bg: require("@/assets/images/DispatchCommand/stitle.png"),
      select: [
        {
          value: "0",
          label: "所有年份",
        },
        {
          value: "1",
          label: "当年",
        },
      ],
      value: "0",
      change: true,
    };
  },
  mounted() {
    this.setEchart();
  },
  methods: {
    setEchart() {
      const _echarts = this.$echarts.init(
        document.getElementById("echartSalesDataMonth")
      );
      const option = {
        tooltip: {
          trigger: "axis",
        },
  legend: {
    data: ["21年", "22年"],
    textStyle: {
            fontSize: 12,
            color: "#fff",
          },
  },
        xAxis: {
          type: "category",
          data: [
            "1月",
            "2月",
            "3月",
            "4月",
            "5月",
            "6月",
            "7月",
            "8月",
            "9月",
            "10月",
            "11月",
            "12月",
          ],
          axisLine: {
            lineStyle: {
              color: "#fff",
            },
          },
          axisLabel: {
            textStyle: {
              color: "#fff",
              fontSize: 12,
            },
          },
        },
        yAxis: {
          type: "value",
          name: "( 万元 )",
          axisLabel: {
            formatter: "{value}",
            textStyle: {
              color: "#fff",
              fontSize: 12,
            },
          },
          axisLine: {
            lineStyle: {
              color: "#fff",
            },
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: ["#305383"],
              width: 1,
              type: "solid",
            },
          },
        },
        grid: {
          top: "20%",
          bottom: "15%",
          right: "5%",
        },
        series: [
          {
            data: [10, 20, 10, 8, 7, 11, 13, 12, 34, 51, 2, 12],
            type: "bar",
            barWidth: 20,
            itemStyle: {
              normal: {
                color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  { offset: 0, color: "rgba(34, 154, 255, 1)" }, //柱图渐变色
                  { offset: 0.5, color: "rgba(34, 154, 255, 0.7)" }, //柱图渐变色
                  { offset: 1, color: "rgba(34, 154, 255, 0.3)" }, //柱图渐变色
                ]),
              },
            },
          },
          {
      name: "21年",
      type: "line",
    smooth:true,
      data: [
        2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3,
      ],
    },
    {
      name: "22年",
      type: "line",
    smooth:true,
      data: [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2],
    },
        ],
      };
      _echarts.setOption(option);
    },
    chbt(type){
      if(type==1){
        this.change = true
      }else if(type==2){
        this.change = false
      }
    }
  },
};
</script>

<style lang="scss" scoped>
.salesDataMonth {
  width: 455px;
  float: left;
  padding-left: 20px;
  box-sizing: border-box;
  .title {
    width: 370px;
  }
  #echartSalesDataMonth {
    width: 100%;
    height: 230px;
  }
  /deep/ .el-select .el-input__inner {
    background-image: url("../../../assets/images/modelimg/slb.png");
    background-repeat: no-repeat;
  background-position: center;
  background-attachment: fixed;
  background-size: cover;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  }
  /deep/ .el-input__inner {
    background-color: unset;
    border: unset;
    color: #fff;
  }
  /deep/ .el-button{
    background:unset;
    background-image: url("../../../assets/images/modelimg/初始.png");
    background-repeat: no-repeat;
  background-position: center;
  background-attachment: fixed;
  background-size: cover;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  color: #fff;
  }
  .xuanzh{
    background-image: url("../../../assets/images/modelimg/点击.png");
    background-repeat: no-repeat;
  background-position: center;
  background-attachment: fixed;
  background-size: cover;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
color: #fff;
  }
}
</style>
